import Worker from 'worker!./worker/worker.ts';

const worker = new Worker();

const container = document.createElement('div');
const button = document.createElement('button');
button.textContent = 'calculate';

document.body.appendChild(container);
document.body.appendChild(button);

let a = Math.round(Math.random() * 100);
let b = Math.round(Math.random() * 100 - 50);

function calculate() {
  a = Math.round(Math.random() * 100 - 50);
  b = Math.round(Math.random() * 100);

  worker.postMessage({ a, b });
}

calculate();

button.onclick = calculate;

worker.onmessage = (e) => {
  container.textContent = `${a} + ${b} = ${e.data}`;
};
